package com.boss.salary.controller;

import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.salary.entity.ExportBankType;
import com.boss.salary.service.IExportBankTypeService;
import com.boss.sys.ca.user.dto.UserDTO;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestSchema(schemaId = "ExportBankTypeController")
@RestController
@RequestMapping(value = "/ExportBankTypeController")
public class ExportBankTypeController extends BasicinfoBaseController {

    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(ExportBankTypeController.class);

    @Autowired
    private IExportBankTypeService exportBankTypeService;



    /**
     * 银行导入保存
     *
     * @param exportBankTypes
     * @return
     */
    @PostMapping("/saveExportBankType")
    public ApiResultDTO saveExportBankType(@RequestHeader("tokenid") String tokenid,
                                                         @RequestBody List<ExportBankType> exportBankTypes) {
        try {
            UserDTO userDTO = getUser(tokenid);
            exportBankTypeService.saveExportBankType(exportBankTypes,userDTO);
            return ApiResultDTO.success(null, "保存成功");
        } catch (Exception e) {
            logger.error(" 单位信息表发生异常", e);
            return ApiResultDTO.error(ERROR_RSCODE, "单位信息表发生异常");
        }
    }
    @GetMapping("/queryPersonTypeSalaryByType")
    public ApiResultDTO queryPersonInfoPage(@RequestHeader("tokenid") String tokenid,
                                            @RequestParam(value = "bankCode", required = false) String bankCode) {
        try {
            List<String> personTypes=new ArrayList<>();
//            personTypes.add(personTypeCode);
            UserDTO userDTO = getUser(tokenid);
            List<ExportBankType> requestList=exportBankTypeService.getInfoByPersonTypes(bankCode,userDTO);
            return ApiResultDTO.success(requestList,null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询失败！");
        }

    }




}
